package cn.sptpc.Controller;

import cn.sptpc.service.ActivityService;
import cn.sptpc.service.impl.ActivityServiceI;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/activity.do")
public class ActivityServlet extends HttpServlet {
    private ActivityService service = new ActivityServiceI();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf8");
        PrintWriter out = response.getWriter();
        String tran = request.getParameter("tran");
        if ("list".equals(tran)){
            String seach = request.getParameter("seach");
            if ("queryActivity".equals(seach)){
                out.print(service.selectActivity(request));
            }else {
                String allUser = service.queryActivity(request);
                out.print(allUser);
            }
        }else if ("select".equals(tran)){
            if("activityInfo".equals(request.getParameter("get"))){
                out.print(service.activityInfo(request));
            }
        }else if ("del".equals(tran)){
            out.print(service.deleteActivity(request));
        }else if ("add".equals(tran)){
            out.print(service.insertActivity(request));
        }else if ("pass".equals(tran)){
            out.print(service.pass(request));
        }else if("refused".equals(tran)){
            out.print(service.refused(request));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
